package fr.generali.accueilclient.gwt.showcase.client.form;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
import com.google.gwt.user.client.Window;

import fr.generali.accueilclient.gwt.client.ui.components.form.Form;

public class FormDemo extends Form implements Editor<ValidableObject>{

    MyDummyPresenter presenter;
    
    private final EditorDriver driver = GWT.create(EditorDriver.class);

    interface EditorDriver extends SimpleBeanEditorDriver<ValidableObject, FormDemo> {
    }
    
    public FormDemo() {
        super();
        this.presenter = new MyDummyPresenter(this);
        driver.initialize(this);
        stubEdition();
    }

    private void stubEdition() {
        ValidableObject validableObject = new ValidableObject();
        driver.edit(validableObject);
    }

    public SimpleBeanEditorDriver<ValidableObject, FormDemo> getEditorDriver() {
        return driver;
    }

    @Override
    public void handleConfirmAction() {
        presenter.doSomeAction();
    }

    @Override
    public void handleCancelAction() {
        Window.alert("Annulation");
    }
}
